package com.hyg.lib_common.Base;

import android.content.Context;
import android.util.Log;

import com.hyg.lib_base.base.MyBaseApplication;
import com.kingsoft.media.httpcache.KSYProxyService;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.litepal.LitePal;
import org.litepal.tablemanager.callback.DatabaseListener;

/**
 * @author: Administrator
 * @date: 2020/12/21
 */
public class BaseApplication  extends MyBaseApplication {

    public static BaseApplication instance;
    private static Context context;

    public  static IWXAPI api;
    public static final String wx_APP_ID = "wxb16002f7defb77ce";
    public static final String wx_secreat_ID = "e59c9c70ab4f2564228befeb5f2b0128";


    public BaseApplication() {

    }

    public static BaseApplication getInstance() {
        return instance;
    }

    public static Context getAppContext() {
        return context;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        instance = this;
        LitePal.initialize(this);
        LitePal.registerDatabaseListener(new DatabaseListener() {
            @Override
            public void onCreate() {
                Log.d("LitePal", "LitePal - onCreate()");
            }
            @Override
            public void onUpgrade(int oldVersion, int newVersion) {
                if (newVersion > oldVersion) {
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            Log.d("LitePal", "LitePal - onUpgrade()");
                        }
                    }).start();
                }
            }
        });
        api= WXAPIFactory.createWXAPI(context,null);
        // 将应用的appId注册到微信
        api.registerApp(wx_APP_ID);
    }


    /**
     * 播放器缓存代理
     *
     * @return
     */
    private KSYProxyService proxy;

    public static KSYProxyService getProxy(Context context) {
        BaseApplication app = (BaseApplication) context.getApplicationContext();
        return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
    }

    private KSYProxyService newProxy() {
        return new KSYProxyService(this);
    }
}
